layui.config({
	base : "js/"
}).use(['form','layer','jquery','laypage','layedit', 'laydate'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
        layedit = layui.layedit,
        laydate = layui.laydate;
		$ = layui.jquery;
    form.verify({  
        firstpwd: [/^[\x21-\x7E]{6,24}$/, '*由6-24位数字,字母或符号组成'],      
        secondpwd: function(value) {
        if(value != $("#firstpwd").val()){
        $("#secondpwd").val("");
        return '确认密码与密码不一致';
        } 
        },      
     });
        
	form.on("submit(createAccount)",function(data){
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        $.ajax({
            type:'post',
            url:'/staff/account/store',
            async:false,
            data:{
                '_token':$('input[name=_token]').val(),
                  "name":$('input[name=name]').val(),
                  "phone":$('input[name=phone]').val(),
                  "email":$('input[name=email]').val(),
                  "pwd":$('input[name=pwd]').val(),
                  "staff_role_id":$('#role').val(),
                  "area_id":$('#area').val()
            },
            dataType:'json',
            success:function (data) {
                console.log(data)
                if(data.status == 1){
                    top.layer.close(index);
                    top.layer.msg("员工添加成功！");
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }else{
                    top.layer.close(index);
                    top.layer.msg("员工添加失败！");
                }
            }
        })
        return false;
    })
})

